package com.jiantong.news.impl.service;

import com.google.common.base.Throwables;
import com.jiantong.news.impl.dao.ThinktankDao;
import com.jiantong.news.impl.dao.ThinktankVideoDao;
import com.jiantong.news.model.Thinktank;
import com.jiantong.news.service.ThinktankWriteService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 养殖智库
 * Created by mz03 on 2017/4/13.
 */


@Slf4j
@Service
@RpcProvider
public class ThinktankWriteServiceImpl implements ThinktankWriteService{

    private final ThinktankDao thinktankDao;
    public ThinktankWriteServiceImpl(ThinktankDao thinktankDao){
        this.thinktankDao = thinktankDao;
    }

    /**
     * 创建
     *
     * @param thinktank 单据对象
     * @return 主键 id
     */
    @Override
    public Response<Long> create(Thinktank thinktank) {
        try {
            thinktankDao.create(thinktank);
            return Response.ok(thinktank.getId());
        }catch (Exception e) {
            log.error("failed.to.create.thinktank:{}", Throwables.getStackTraceAsString(e));
            return Response.fail("create.thinktank.failed");
        }
    }

    /**
     * 更新
     *
     * @param thinktank 单据对象
     * @return true or false
     */
    @Override
    public Response<Boolean> update(Thinktank thinktank) {
        try{
            return Response.ok(thinktankDao.update(thinktank));
        }catch (Exception e){
            log.error("failed.to.update.thinktank:{}",Throwables.getStackTraceAsString(e));
            return Response.fail("update.thinktank.failed");
        }
    }
}
